def addmatrix():
    import tkinter as tk
    linearwindow1=tk.Tk()
    linearwindow1.title("AddMatrix")
    linearwindow1.geometry("600x700")    
    def lie():
        lie=eval(e1.get())
    def smatrix1():
        global ma1
        ma1=eval(e2.get())
    def smatrix2():
        global ma2
        ma2=eval(e3.get())
    def dadm():
        lie=eval(e1.get())

        adma=[]        
#        print(ma1)
#        print(ma2)
        le=len(ma1)
#        print(le)
        co=0
        i=0
        if len(ma1)==len(ma2) and len(ma1)>0 and len(ma2)>0 and (len(ma1)%lie)==(len(ma2)%lie) and len(ma1)%lie==0 and len(ma2)%lie==0:
            while i<=le-1:
                adma.append(ma1[i]+ma2[i])
                i=i+1
    #        print(adma)
            i=0
            while i<=le-1:
                tx.insert('insert',adma[i])
                co=co+1
                if co%lie!=0:
                    tx.insert('insert','\t')
                if co%lie==0:
                    tx.insert('insert','\n')
                i=i+1
            tx.insert('insert','\n')
        else:
            tx.insert('insert',"结论：数据有误，非同型矩阵，不能相加！")
    e1 = tk.Entry(linearwindow1,font=('Arial', 14))
    e1.pack()
    bt1=tk.Button(linearwindow1,text='确认列数',width=10,height=1,font=('Arial', 10),command=lie)
    bt1.pack()
    
    lb1=tk.Label(linearwindow1, text='在[]中以英文逗号分隔元素：\nexamp:[1,2,3,4,5,6]', bg='orange', font=('Arial', 12), width=30, height=2)
    lb1.pack()
    e2 = tk.Entry(linearwindow1,font=('Arial', 14))
    e2.pack()
    bt2=tk.Button(linearwindow1,text='确认矩阵A',width=10,height=1,font=('Arial', 10),command=smatrix1)
    bt2.pack()
    
    lb2=tk.Label(linearwindow1,text='在[]中以英文逗号分隔元素：\nexamp:[1,2,3,4,5,6]', bg='orange', font=('Arial', 12), width=30, height=2)
    lb2.pack()
    e3 = tk.Entry(linearwindow1,font=('Arial', 14))
    e3.pack()
    bt3=tk.Button(linearwindow1,text='确认矩阵B',width=10,height=1,font=('Arial', 10),command=smatrix2)
    bt3.pack()
    
    lb3=tk.Label(linearwindow1,text='------------------------------------------------------', bg='orange', font=('Arial', 12), width=30, height=1)
    lb3.pack()
    bt4=tk.Button(linearwindow1,text='矩阵相加',width=10,height=1,font=('Arial', 10),command=dadm)
    bt4.pack()
    lb4=tk.Label(linearwindow1,text='【A+B=C】C=：', bg='orange', font=('Arial', 12), width=30, height=2)
    lb4.pack()
    
    tx=tk.Text(linearwindow1,width=38,height=30)
    tx.pack()
    linearwindow1.mainloop()